<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>京东精选</title>
<link rel="stylesheet" type="text/css"
	href="../../global/icon/iconfont.css" />
<link rel="stylesheet" type="text/css"
	href="../../global/ui/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css"
	href="../../global/ui/bootstrap/css/bootstrap-datetimepicker.min.css" />
<link rel="stylesheet" type="text/css"
	href="../../global/ui/bootstrap/css/ui.jqgrid-bootstrap.css">
<link rel="stylesheet" type="text/css"
	href="../../global/ui/layer/skin/layer.css">
<link rel="stylesheet" type="text/css" href="../../global/css/user.css">
<link rel="stylesheet" type="text/css" href="../../global/css/style.css">
<style>
.btnBox1 button i {
	padding-right: 0px;
}

.btnBox1 button {
	margin-left: 10px;
}

#confirm {
	margin-left: 15px;
}

.table>tbody>tr>td {
	padding: 8px 0 0 12px;
	font-size: 12px;
}
</style>
</head>
<body>

	<div style="width: 100%; height: 100%;" class="Dict">
		<!--   右边为iframe内容区-->
		<div
			style="float: left; width: 100%; height: 100%; background: #e1eae8;">
			<div class="contteruser margintopf" id="contteruser">
				<div class="contter_user">
					<div class="table_yh">
						<div class="allboxTit">
							<span>京东精选</span>
						</div>
						<div class="btnBox3">
							<div class="btnBox1">
								<button id="updatedict" permission="sys:dict:update" style="margin-left: 7px">
									<i class="iconfont icon-tuihui"></i>修改
								</button>
							</div>
						</div>
						<div class="contentMid">
							<div class="jqgrid1a">
								<table id="jqgrid1"></table>
							</div>
							<div id="jqgrid1Pager"></div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div style="padding-top: 10px; display: none; text-align: left"
			class="choiceB-3">
			<div class="contentTop1">
				<form class="form-horizontal" onsubmit="return false" id="form"  enctype="multipart/form-data">
				<input type="hidden" id="id" />
				<div style="margin-bottom: 6px">
					<label style="width: 100px; margin-left: 20px;">商品名称：</label> <input
						type="text" style="width: 210px; height: 24px;" id="goodsName" readonly
						class="checkOnly" />
				</div>
				<div style="margin-bottom: 6px">
					<label style="width: 100px; margin-left: 20px;">是否置顶：</label> <input
						type="text" style="width: 210px; height: 24px;" id="attName" />
				</div>
				<div style="margin-bottom: 6px">
					<label style="width: 100px; margin-left: 20px;">是否首页：</label> <input
						type="text" style="width: 210px; height: 24px;" id="dictCode"
						class="checkOnly" />
				</div>
				<div style="margin-bottom: 6px">
					<label style="width: 100px; margin-left: 20px;">banner上传：</label> <input
						type="text" style="width: 210px; height: 24px;" id="remarks" />
				</div>
				<div style="margin-bottom: 6px">
					<label style="width: 20px;"></label> <span id="ErrorMsg1"
						style="color: red;"></span>
				</div>
				</form>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript"
	src="../../global/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="../../global/js/jquery-tab.js"></script>
<script type="text/javascript"
	src="../../global/ui/bootstrap/js/i18n/grid.locale-cn.js"></script>
	<script type="text/javascript" src="../../global/js/common.js"></script>
	<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript"
	src="../../global/ui/bootstrap/js/jquery.jqGrid.js"></script>
<script type="text/javascript" src="../../global/ui/layer/layer.min.js"></script>
<script type="text/javascript" src="../../global/js/my/permission.js"></script>
<script>

        $(function(){//初始化tab切换按钮控件
          $('.tab-group').tabify();
          $.ajax({
		        type: "POST",
		        url:"../../clyjChoice/getAllData",
		        contentType : "application/json; charset=utf-8",
		        dataType:"json",
		        async: true,
		        success:function(obj2){
				}
				
		    });
        })

        $ ('body').delegate('.J_menuItem','click',function (){
            var o = $(this).attr("href"),
                    m = $(this).data("index"),
                    l = $.trim($(this).text());
            var p = '<a href="javascript:;" class="active J_menuTab" data-id="' + o + '">' + l + ' <i class="fa fa-times-circle"></i></a>';
            $(".J_menuTab").removeClass("active");
            var n = '<iframe class="J_iframe" name="iframe' + m + '" width="100%" height="100%" src="' + o + '" frameborder="0" data-id="' + o + '" seamless></iframe>';
            $(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(n);
            $(".J_menuTabs .page-tabs-content").append(p);
            layer.closeAll();
            return false;
        });
        $ ('body').delegate('.layui-layer-tips','mouseleave',function (){
            layer.closeAll();
        });
        //      页面加载时内容区域宽度变化
         $(".navbar-static-side").resize(function(){
             if($(".ul_li").width() > 50){
                 layer.closeAll();
             }
         });

    $(document).ready(function(){
    	var pers = checkPermission();
		pageInitJqgrid2();
	});
  //初始化加载数据   
    function pageInitJqgrid2(){
            $("#jqgrid1").jqGrid({
                url : '../../selectDictionaries',
                datatype: "json",
                styleUI:"Bootstrap",
                colNames : ['字典编码', '字典名称','上级字典编码','排序号','层级','备注',''],
                colModel : [
    				{name : 'attcode',index : 'attcode',width : 60},
                    {name : 'attname',index : 'attname',width : 60},  
                    {name : 'pcode',index : 'pcode',width : 60}, 
                    {name : 'sortNo',index : 'sortNo',width : 60},
                    {name : 'ditLevels',index : 'ditLevels',width : 60},
                    {name : 'remarks',index : 'remarks',width : 60},
                    {name : 'id',index : 'id',width : 60,hidden:true}, //id保存页面隐藏为删除时使用
                ],
                rowNum : 10, //每页显示的条目数
                height:'auto',   //行高自动增加
                rowList : [ 10, 20, 30 ],//和rownum同步设置才能控制每页显示行数
                pager : '#jqgrid1Pager',  //分页使用
                altRows:true,
                recordpos : 'right',  //条目数标示的位置
                loadonce: true,
                viewrecords : true,
                multiselect : true,//复选框
                autowidth:true,    
                sortorder: "desc",//默认的数据排序
                forceFit: true,
                cellsubmit: 'clientArray',
                cellEdit: false,
    			gridComplete:function(data,row_id) {
    				
                }
            });
            jQuery("#jqgrid1").jqGrid('navGrid', '#pager9', {
                add : false,
                del : false,
                edit : false,
                position : 'right'
            });
        }
        //页面的父元素宽度变化时  table自适应宽度事件
        $(".jqgrid1a").resize(function(){
            $("#jqgrid1").setGridWidth($(".jqgrid1a").width());
    	})
    	
	//插入
	 $("#confirm").click(function(){
		 //清空输入框及提示和表格的锁定状态
		 $("#id").val("");
		 $("#attName").val("");
     	 $("#attCode").val("");
     	 $("#dictCode").val("");
     	 $("#sequence").val("");
     	 $("#level").val("");
     	 $("#remarks").val("");
     	
     	 $("#ErrorMsg1").text("");
		 $("#attCode").removeAttr("disabled");
		 
		 layer.open({
	            type: 1,
	            skin: 'layui-layer-gray',
	            fix: true,
	            title: ["添加字典","background:#1cb194;color:#fff;font-weight:bold"],
	            shadeClose: false,
	            scrollbar:false,
	            area: ['420px', '320px'],
	            shift: 5,
	            content: $('.choiceB-3'),
	            btns: 2,
	            btn: ['确定','取消'],
	            yes: function(index){
	            	//错误提示的判断
	            	if($("#ErrorMsg1").text()!=""&&$("#ErrorMsg1").text()!=null){
	       			 layer.msg("验证重复", {time: 3000,icon: 2 });
	       			 return;
	       		 }
	            	var attCode = $("#attCode").val();
	            	//字典编码判断
	            	if(attCode == ""){
	            		layer.msg("字典编码为空",{icon:2});
	            		return;
	            	}
	            	var attName = $("#attName").val();
	            	//字典名称判断
	            	if(attName == ""){
	            		layer.msg("字典名称为空",{icon:2});
	            		return;
	            	}
	            	var dictCode = $("#dictCode").val();
	            	var sequence = $("#sequence").val();
	            	//字典排序号判断
	            	if(sequence == ""){
	            		layer.msg("排序号为空",{icon:2});
	            		return;
	            	}
	            	var level = $("#level").val();
	            	if(level == ""){
	            		layer.msg("层级为空",{icon:2});
	            		return;
	            	}
	            	var remarks = $("#remarks").val();
	            	var obj = {"attName":attName,"attCode":attCode,
	    					"dictCode":dictCode,"sequence":sequence,"level":level,"remarks":remarks};
	    			$.ajax({
	    		        cache: true,
	    		        type: "POST",
	    		        url:"../../insertDictionaries",
	    		        data:JSON.stringify(obj),
	    		        contentType : "application/json; charset=utf-8",
	    		        dataType:"json",
	    		        async: true,
	    		        success:function(obj2){
	    		        	data = obj2.data;
	    		        	if(data.flag == "S"){
	    		        		//刷新jqgrid
	    		        		$("#jqgrid1").jqGrid('setGridParam',{
	    		        			url : '../../selectDictionaries',
	    		                    datatype: "json",
					       		}).trigger("reloadGrid");
	    		        		layer.msg(data.message, {time: 3000,icon: 1 });
	    		        	}else{
	    		        		layer.msg(data.message, {time: 3000,icon: 2 });
	    		        	}
	    				}
	    				
	    		    });
	                layer.close(index);
	            }
	        })
		}); 
	 //修改
	 $("#updatedict").click(function(){
		 
		 var rows = $("#jqgrid1").jqGrid('getGridParam','selarrrow');
		 //判断是否只有一条数据
		 if(rows.length != 1){
			 layer.msg('请选择一条数据',{icon:2});
			 return;
		 }
		 //得到修改的数据
		 var rowData = $('#jqgrid1').jqGrid('getRowData',rows);
		
		 //弹出框内容赋值
		 document.getElementById("attName").value=rowData.attname;
		 document.getElementById("attCode").value=rowData.attcode;
		 document.getElementById("dictCode").value=rowData.pcode;
		 document.getElementById("sequence").value=rowData.sortNo;
		 document.getElementById("level").value=rowData.ditLevels;
		 $("#remarks").val(rowData.remarks);
		 $("#id").val(rowData.id);
		//清除状态和错误提示
		 $("#ErrorMsg1").text("");
     	 //$("#attCode").attr("disabled",'disabled');
     	 $("#dictCode").attr("disabled",'disabled');
		 layer.open({
	            type: 1,
	            skin: 'layui-layer-gray',
	            fix: true,
	            title: ["修改字典","background:#1cb194;color:#fff;font-weight:bold"],
	            shadeClose: false,
	            scrollbar:false,
	            area: ['420px', '320px'],
	            shift: 5,
	            content: $('.choiceB-3'),
	            btns: 2,
	            btn: ['确定','取消'],
	            yes: function(index){
	            	//错误提示的判断
	            	if($("#ErrorMsg1").text()!=""&&$("#ErrorMsg1").text()!=null){
	       			 layer.msg("验证重复", {time: 3000,icon: 2 });
	       			 return;
	       		 }
	            	var attName = $("#attName").val();
	            	var attCode = $("#attCode").val();
	            	var dictCode = $("#dictCode").val();
	            	var sequence = $("#sequence").val();
	            	var level = $("#level").val();
	            	var remarks = $("#remarks").val();
	            	var obj = {"id":rowData.id,"attName":attName,"attCode":attCode,
	    					"dictCode":dictCode,"sequence":sequence,"level":level,"remarks":remarks};
	    			$.ajax({
	    		        cache: true,
	    		        type: "POST",
	    		        url:"../../updateDictionaries",
	    		        data:JSON.stringify(obj),
	    		        contentType : "application/json; charset=utf-8",
	    		        dataType:"json",
	    		        async: true,
	    		        error: function(data) { 		        
	    		        },
	    		        success:function(data){
	    		        	if(data.flag == "S"){
	    		        		$("#jqgrid1").jqGrid('setGridParam',{
	    		        			url : '../../selectDictionaries',
	    		                    datatype: "json",
					       		}).trigger("reloadGrid");
	    		        		layer.msg(data.message, {time: 3000,icon: 1 });
	    		        	}else{
	    		        		layer.msg(data.message, {time: 3000,icon: 2 });
	    		        	}
	    				}
	    				
	    		    });
	                layer.close(index);
	            },
	            no: function(index){
	            	layer.close(index);
	            }
	        })
	 })
	 //返回首页
	 $("#shouye").click(function(){
		 location.href="../../goMain1";
	 })
	 //获取焦点清除错误提示
	 if(ErrorMsg1 != ""){
		 $(".checkOnly").focus(function(){
			 $("#ErrorMsg1").text("");
		 }) 
	 }
	 //失去焦点验证字典编码
	 $(".checkOnly").blur(function(){
         var attCode = $("#attCode").val();
         var dictCode = $("#dictCode").val();
         if(attCode==null||attCode==""){
        	 return;
         }
         var id = $("#id").val();
		 var obj ={"attCode":attCode,"dictCode":dictCode,"id":id};
         	$.ajax({
		        cache: true,
		        type: "POST",
		        url:"../../compareValue",
		        data:JSON.stringify(obj),
		        contentType : "application/json; charset=utf-8",
		        dataType:"json",
		        async: true,
		        error: function(data) {
		        },
		        success:function(data){
		        	if(data.flag == "CODE"){
		        		$("#ErrorMsg1").text("字典编码重复！");
		        		//禁用确定按钮
		        	}
		        }
		    });
	 })
	 
	 //删除
	 $("#deleteDict").click(function(){
		var rows = $("#jqgrid1").jqGrid('getGridParam','selarrrow');
		 if(rows.length < 1){
			 layer.msg('请选择删除的数据',{icon:2});
			 return;
		 }
		 var rowData = new Array();
		 //获取选中的需求单
		 for(var i=0;i<rows.length;i++){
			 rowData.push( $('#jqgrid1').jqGrid('getRowData',rows[i]).id);
		 }
		 var obj ={"rowData":rowData};
		layer.confirm('您是否确定删除？', {
			  btn: ['确定','返回'],
			  title: ["删除提示","background:#1cb194;color:#fff;font-weight:bold"],
			  shadeClose:false,
			  success: function(){
                $(".layui-layer-content").css({
                    "height":"70px",
                    "text-align":"center",
                    "line-height":"70px",
                    "padding": "0",
                    "color":"#323232"
                })
			  }
			}, function(){
				$.ajax({
        	        cache: true,
        	        type: "POST",
        	        url:"../../deleteDictionaries",
        	        data:JSON.stringify(obj),
        	        contentType : "application/json; charset=utf-8",
        	        dataType:"json",
        	        async: true,
        	        error: function(data) {
        	        },
        	        success:function(data){
        	        	if(data.flag == "S"){
        	        		//成功后重新加载grid
        	        		$("#jqgrid1").jqGrid('setGridParam',{
        	        			url : '../../selectDictionaries',
        	                    datatype: "json",
        		       		}).trigger("reloadGrid");
        	        		layer.msg(data.message, {time: 3000,icon: 1 });
        	        	}else{
        	        		layer.msg(data.message, {time: 3000,icon: 2 });
        	        	}
        			}
        			
        	    });
			}, function(){
				layer.closeAll();
			});
		})
  </script>
</html>
